package com.aya.base.job.module.job;

import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class StartUpSchedulerListener implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    Scheduler scheduler;
    @Resource
    ApplicationContext applicationContext;
    @Resource
    List<Trigger> triggers;
    @Resource
    List<JobDetail> jobDetails;

    /**
     * 不能在这个阶段删除任务
     * @param event
     */
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
//        try {
//            Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.anyGroup());
//            scheduler.deleteJobs(new ArrayList<>(jobKeys));
//        } catch (SchedulerException e) {
//            e.printStackTrace();
//        }
    }
}
